<?php
/**
* This View is used by all Scribble admin UIs. For none-admin UIs use
* ScribblePublicView instead.
*
* Copyright (c) 2009 James Gauld <james@jamesgauld.net>
* This file is part of Scribble.
* @license http://www.scribblecms.co.uk/license.txt
*
* @package Scribble
*/
use Buan\Config;
use Buan\View;
use Buan\PhpViewEngine;
use Buan\ViewHelper\Html as HtmlHelper;
class ScribbleAdminView extends View {

	/**
	* Constructor.
	*
	* @param Buan\IViewEngine A rendering engine instance
	* @return ScribbleAdminView
	*/
	public function __construct($engine=NULL) {

		// If $engine is unspecified, then default to using our own
		if($engine===NULL) {
			$engine = new PhpViewEngine();
		}
		parent::__construct($engine);

		// Load and prepare the HTML helper
		$this->loadHelper('html');
		$this->helpers->html->setUrlSuffix(Config::get('ext.Scribble.urlSuffix'));

		// Load and prepare the i18n helper
		$this->loadHelper('i18n');
		$this->helpers->i18n->addDictionaryFolder(dirname(dirname(__FILE__)).'/lang');
		if(ScribbleSession::isOccupied()) {
			$this->helpers->i18n->setLanguage(ScribbleSession::getUser()->getPreferences()->get('adminLanguage'));
		}

		// TODO: Plugins need a way of adding their own dictionaries.
	}

	/**
	* Prepares a few things for displaying $this view in a popup dialog window.
	*
	* @return void
	*/
	public function popup() {

		// Set the GlobalView to use the popup-specific template
		View::getGlobalView()->setSource(Config::get('ext.Scribble.dir.views').'/global-view/index.popup.tpl.php');
	}
}
?>